package seu.xml.analysis;

import java.util.HashSet;
/**
 * UML图关系类，用于表示UML图中的所有线条
 * @author cy
 *
 */
public class UMLRelation {
	private int id;	////唯一标识id
	private int startEntityID;//起点关联的实体id
	private int endEntityID;//终点关联的实体id
	private int startRelationID;//起点关联的关系id
	private int endRelationID;//终点关联的关系id
	//关系的起点和终点坐标值
	private int xStart;
	private int yStart;			
	private int xEnd;
	private int yEnd;
	
	public Element UMLRelationElement;//保存Element全部内容
	
	public HashSet<Integer> externalEntity;//存储该关系所在的外部实体（外部嵌套）
	public HashSet<Integer> relevanceRelation;//存储关联的关系（如生命线可能关联很多关系）
	/**
	 * UMLRelation构造函数
	 * @param id UMLRelation唯一标识id
	 * @param e 实体元素
	 */
	public UMLRelation(int id,Element e){
		this.id = id;
		this.UMLRelationElement = e;
		startEntityID = -1;
		endEntityID = -1;
		startRelationID = -1;
		endRelationID = -1;
		externalEntity = new HashSet<Integer>();
		relevanceRelation = new HashSet<Integer>();
		String[] s = UMLRelationElement.getAdditional_attributes().split(";");
		xStart = UMLRelationElement.getX()+Integer.parseInt(s[0]);
		yStart = UMLRelationElement.getY()+Integer.parseInt(s[1]);			
		xEnd = UMLRelationElement.getX()+Integer.parseInt(s[s.length-2]);
		yEnd = UMLRelationElement.getY()+Integer.parseInt(s[s.length-1]);
	}
	/**
	 * 判断点(a,b)是否在该关系上
	 * @param a 点的x坐标
	 * @param b	点的y坐标
	 * @return 点在该关系上，返回true，否则返回false
	 */
	public boolean hasPoint(int a,int b){		
		if(((b-yStart)*(xEnd-xStart)-(yEnd-yStart)*(a-xStart)==0)&&((a-xStart)*(a-xEnd)<=0)&&(b-yStart)*(b-yEnd)<=0){
			return true;
		}
		else
			return false;
	}
	public int getStartRelationID() {
		return startRelationID;
	}
	public void setStartRelationID(int startRelationID) {
		this.startRelationID = startRelationID;
	}
	public int getEndRelationID() {
		return endRelationID;
	}
	public void setEndRelationID(int endRelationID) {
		this.endRelationID = endRelationID;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getStartEntityID() {
		return startEntityID;
	}
	public void setStartEntityID(int startEntityID) {
		this.startEntityID = startEntityID;
	}
	public int getEndEntityID() {
		return endEntityID;
	}
	public void setEndEntityID(int endEntityID) {
		this.endEntityID = endEntityID;
	}
	public int getxStart() {
		return xStart;
	}
	public void setxStart(int xStart) {
		this.xStart = xStart;
	}
	public int getyStart() {
		return yStart;
	}
	public void setyStart(int yStart) {
		this.yStart = yStart;
	}
	public int getxEnd() {
		return xEnd;
	}
	public void setxEnd(int xEnd) {
		this.xEnd = xEnd;
	}
	public int getyEnd() {
		return yEnd;
	}
	public void setyEnd(int yEnd) {
		this.yEnd = yEnd;
	}
	
}
